package com.kfgj.hkp.manager.customer.strategy;

import com.kfgj.hkp.entity.customer.CustomerEntity;
import com.kfgj.hkp.entity.systemconfig.FocusCusConfig;
import com.kfgj.hkp.entity.user.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 集中获客策略上下文
 */
@Component
public  class FocusCusStrategyContext  {
    private final Map<String, FocusCusStrategy> strategyMap = new ConcurrentHashMap<> ();

    @Autowired
    public FocusCusStrategyContext (Map<String, FocusCusStrategy> strategyMap) {
        this.strategyMap.clear ();
        strategyMap.forEach (this.strategyMap :: put);
    }


    public List<UserEntity> addTargetUsersForFocusCus (CustomerEntity customer, List<UserEntity> targetUsers, FocusCusConfig focusCusConfig) {

       return addTargetUsersForFocusCus(customer,targetUsers,focusCusConfig.getStrategy(),focusCusConfig);
    }

    public List<UserEntity> addTargetUsersForFocusCus (CustomerEntity customer, List<UserEntity> targetUsers, String focusCusStrategy, FocusCusConfig focusCusConfig) {
        FocusCusStrategy strategy = strategyMap.get(focusCusStrategy);
        strategy.setSecondStrategy(strategyMap.get(focusCusConfig.getSecondStrategy()));
        return this.strategyMap.get (focusCusStrategy).handle (customer, targetUsers, focusCusConfig);
    }



}
